#1.定位到2020必看电影
#2.从2022必看电影中提取到子页面的链接
#3.请求子页面的链接地址。拿到我们想要的下载地址
import requests
import  re
domain = "https://dydytt.net/index.htm"
resp = requests.get(domain)
resp.encoding = 'gb2312'
# print(resp.text)

odj1=re.compile(r'2023新片精品.*?<ul>.*?<table width="100%" border="0" cellspacing="0" cellpadding="0">'
                r'(?P<ul>.*?)</table>',re.S)
obj2=re.compile(r"""<a href="/html/gndy/dyzz/index.html">最新电影下载</a>]<a href='(?P<href>.*?)'""",re.S)
obj3=re.compile(f'◎片　　名(?P<movie>.*?)<br />.*? target="_blank" href="(?P<downlaod>.*?)"><strong style='
                f'',re.S)

result1=odj1.finditer(resp.text)
#拿到ul里的tr
child_href_list=[]
for it in result1:
    ul=it.group("ul")
    result2=obj2.finditer(ul)
    for itt in result2:
        # print(itt)
        # print(itt.group("href"))
        #拼接子页面的url地址：域名+子页面地址
        child_href="https://dydytt.net"+ itt.group("href")
        # print(child_href)
        child_href_list.append(child_href)
#提取子页面内容
# print(child_href_list)
for href in child_href_list:
    # print(href)
    child_resp=requests.get(href)
    child_resp.encoding="gb2312"
    # print(child_resp.text)
    result3 = obj3.search(child_resp.text)
    print(result3.group("movie"))
    print(result3.group("downlaod"))
    # break
